<?php
namespace api\bdd;

class DatabaseConnection 
{
	public static function get()
	{
		static $db = null;
		if ( $db == null )
			$db = new DatabaseConnection();
		return $db;
	}
	
	private $_handle = null;
	
	private function __construct()
	{
		$dsn = BDD_SGBD . ':host=' . BDD_HOST .';dbname=' . BDD_BASE;
		
		try {
			$this->_handle = new \pdo( $dsn , BDD_USER , BDD_PASS );
		} catch (\Exception $e) {
			throw new api\exception\BddException('Connection impossible');
		}
	}
	
	//public function query (api\bdd\table\iTable
	
	public function handle()
	{
		return $this->_handle;
	}
}